using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace AlgorithmsVisualized
{
    public class Util
    {
        public static Point TransformToCenter(Point p, int Width, int Height)
        {
            return new Point(p.X - Width / 2, p.Y - Height / 2);
        }
        public static Point Subtract(Point p1, Point p2)
        {
            return  new Point(p1.X - p2.X, p1.Y - p2.Y);
        }

        internal static double VectorLength(Point vec)
        {
            return Math.Sqrt(vec.X * vec.X + vec.Y * vec.Y);
        }

        internal static double ToRadians(double Angle)
        {
            return Angle * Math.PI / 180;
        }

        internal static Point ShiftInDirection(Point ToShift, int Shift, Point LookAt)
        {
            Point New = ToShift;
            Point vec = Util.Subtract(ToShift, LookAt);
            double len = Util.VectorLength(vec);
            New.Y = (int)((len - Shift) * (ToShift.Y - LookAt.Y) / len) + LookAt.Y;
            New.X += (int)((len - Shift) * vec.X / len) - vec.X;
            return New;
        }
    }
}
